﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Text;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AutoClick
{
    /// <summary>
    /// Logique d'interaction pour WPFAutoClickTypes.xaml
    /// </summary>
    public partial class WPFAutoClickTypes : Window
    {
        #region Attributes
        public delegate void NewTypeOfClickSelected(string kindOfClick);
        public event NewTypeOfClickSelected NewSelection;
        private ResourceManager _resourceForText;
        #endregion

        #region Constructor
        public WPFAutoClickTypes(String typeOfClick, ResourceManager resource)
        {
            InitializeComponent();

            //Set language
            _resourceForText = resource;
            AddText();

            //Place the window
            this.Left = (Screen.PrimaryScreen.Bounds.Width / 2) - (this.Width / 2);
            this.Top = 25;

            //Initialize the selection of type of click
            switch (typeOfClick)
            {
                case "clickLeft":
                    TypeSelected(_textBlock1);
                    break;
                case "clickRight":
                    TypeSelected(_textBlock2);
                    break;
                case "clickDoubled":
                    TypeSelected(_textBlock3);
                    break;
                case "clickHold":
                    TypeSelected(_textBlock4);
                    break;
                case "noClick":
                    TypeSelected(_textBlock6);
                    break;
                case "gesture":
                    TypeSelected(_textBlock5);
                    break;
            }
        }
        #endregion

        #region Methods for type of click's selection
        /// <summary>
        /// Method that changes the selection on the menu of types of click
        /// </summary>
        /// <param name="textBlock"></param>
        public void TypeSelected(TextBlock textBlock)
        {
            if (textBlock != _textBlock1)
                _textBlock1.Background = Brushes.Transparent;
            if (textBlock != _textBlock2)
                _textBlock2.Background = Brushes.Transparent;
            if (textBlock != _textBlock3)
                _textBlock3.Background = Brushes.Transparent;
            if (textBlock != _textBlock4)
                _textBlock4.Background = Brushes.Transparent;
            if (textBlock != _textBlock6)
                _textBlock6.Background = Brushes.Transparent;
            if (textBlock != _textBlock5)
                _textBlock5.Background = Brushes.Transparent;

            textBlock.Background = Brushes.Silver;
        }

        // Update selection
        private void textBlock1_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            TypeSelected(_textBlock1);
            NewSelection("clickLeft");
        }
        private void textBlock2_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            TypeSelected(_textBlock2);
            NewSelection("clickRight");
        }
        private void textBlock3_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            TypeSelected(_textBlock3);
            NewSelection("clickDoubled");
        }
        private void textBlock4_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            TypeSelected(_textBlock4);
            NewSelection("clickHold");
        }
        private void textBlock5_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            TypeSelected(_textBlock6);
            NewSelection("noClick");
        }
        private void textBlock6_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            TypeSelected(_textBlock5);
            NewSelection("gesture");
        }
        #endregion

        #region Set text
        /// <summary>
        /// Add the text on WPF according to the language of user's OS
        /// </summary>
        public void AddText()
        {
            _textBlock1.Text = (String)_resourceForText.GetObject("clickLeft");
            _textBlock2.Text = (String)_resourceForText.GetObject("clickRight");
            _textBlock3.Text = (String)_resourceForText.GetObject("clickDoubled");
            _textBlock4.Text = (String)_resourceForText.GetObject("clickHold");
            _textBlock5.Text = (String)_resourceForText.GetObject("gestureClick");
            _textBlock6.Text = (String)_resourceForText.GetObject("noClick");
            _textBlock7.Text = (String)_resourceForText.GetObject("chooseClick");
        }
        #endregion

        private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }  
    }
}
